home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / T / TIFF Code.cpt / dofile.c < prev    next >
Text File  |  1987-12-16  |  4KB  |  188 lines

  1. /* Standard C Include files */
  2. /* #include "CType.h" */
  3. /* #include "ErrNo.h" */
  4. /* #include "FCntl.h" */
  5. /* #include "IOCtl.h" */
  6. /* #include "Math.h" */
  7. /* #include "SetJmp.h" */
  8. /* #include "Signal.h" */
  9. /* #include "StdIO.h" */
  10. /* #include "String.h" */
  11.  
  12. /* Primary Interface Files */
  13. #include "Types.h"
  14. #include "Resources.h"
  15. #include "Quickdraw.h"
  16. #include "Windows.h"
  17. /* #include "OSUtils.h" */
  18.  
  19. /* Commonly Included files */
  20. /* #include "ToolUtils.h" */
  21. #include "TextEdit.h"
  22. /* #include "Controls.h" */
  23.  
  24. /* Other Interface files */
  25. /* #include "AppleTalk.h" */
  26. /* #include "CursorCtl.h" */
  27. /* #include "Desk.h" */
  28. /* #include "DeskBus.h" */
  29. /* #include "Devices.h" */
  30. /* #include "Dialogs.h" */
  31. /* #include "DiskInit.h" */
  32. /* #include "Disks.h" */
  33. /* #include "ErrMgr.h" */
  34. #include "Errors.h"
  35. /* #include "Events.h" */
  36. #include "Files.h"
  37. /* #include "Fonts.h" */
  38. /* #include "Graf3D.h" */
  39. /* #include "Lists.h" */
  40. #include "Memory.h"
  41. /* #include "Menus.h" */
  42. #include "Packages.h"
  43. /* #include "Palette.h" */
  44. /* #include "Perf.h" */
  45. /* #include "Picker.h" */
  46. /* #include "Printing.h" */
  47. /* #include "Retrace.h" */
  48. /* #include "ROMDefs.h" */
  49. /* #include "SANE.h" */
  50. #include "Scrap.h"
  51. /* #include "Script.h" */
  52. /* #include "SCSI.h" */
  53. /* #include "SegLoad.h" */
  54. /* #include "Serial.h" */
  55. /* #include "Slots.h" */
  56. /* #include "Sound.h" */
  57. /* #include "Start.h" */
  58. /* #include "Strings.h" */
  59. /* #include "Time.h" */
  60. /* #include "Traps.h" */
  61. /* #include "Values.h" */
  62. /* #include "VarArgs.h" */
  63. /* #include "Video.h" */
  64.  
  65. /* Application-specific Include files */
  66. #include "::TiffLibrary:TIFFLib.h"
  67. #include "sample.h"
  68. #include "messages.h"
  69.  
  70. /*
  71.  * Definitions and Declarations
  72.  */
  73.  
  74. Point where = {34,80};
  75. StatString(putPrompt, "Save current document as:");
  76. StatString(getPrompt, "Save current document as:");
  77. StatString(untitled, "Untitled");
  78. static Int16 refNum = -1;            /* currently opened file's refNum */
  79. Str63 currentFName = {0,""};
  80. SFReply    reply;
  81.  
  82. #define    NUMTYPES    2                /* number of file types for SFGETFILE */
  83. SFTypeList MyTypeList = {            /* types of files to open */
  84.     'TIFF',
  85.     'SPTG'
  86. };
  87.  
  88. void DoOpen(myBitMapPtr)
  89. BitMap        *myBitMapPtr;
  90. {
  91.     WindowPtr    theActiveWindow;
  92.     
  93.     if (refNum > 0) {
  94.         ErrorMessage(FILEOPEN);
  95.         return;
  96.     }
  97.     SFGETFILE(where, &getPrompt, nil, (Int16)NUMTYPES, MyTypeList, nil, &reply);
  98.     if (reply.good == false)
  99.         return;
  100.     /* Set current file name to that just selected */
  101.     currentFName = *((Str63 *)(&(reply.fName)));
  102.     if ((FSOPEN(¤tFName, reply.vRefNum, &refNum)) != noErr) {
  103.         ErrorMessage(BADOPEN);
  104.         refNum = -1;
  105.         return;
  106.     }
  107.     if (ReadTiff(refNum, myBitMapPtr)) {
  108.         theActiveWindow = FrontWindow();
  109.         SETWTITLE(theActiveWindow, ¤tFName);
  110.     }
  111.     else {
  112.         DoClose();
  113.         ClearImage(myBitMapPtr);
  114.     }
  115. }
  116.  
  117. void DoClose()
  118. {
  119.     if (refNum >= 0) {                        /* no file open */
  120.         if (FSClose(refNum) != noErr) {
  121.             ErrorMessage(BADCLOSE);
  122.             return;
  123.         }
  124.         if (FLUSHVOL(nil, reply.vRefNum) != noErr) {
  125.             ErrorMessage(BADFLUSHVOL);
  126.             return;
  127.         }
  128.         refNum = -1;                        /* -1 means no file open */
  129.         currentFName.length = 0;
  130.         SETWTITLE(FrontWindow(), &untitled);
  131.     }
  132. }
  133.  
  134. void DoSave(MyBitMapPtr)
  135. BitMap *MyBitMapPtr;
  136. {
  137.     if (refNum < 0) {        /* No currently open file */
  138.         DoSaveAs(MyBitMapPtr);
  139.     }
  140.     else {
  141.         /* truncate file to zero length */
  142.         if ((SetEOF(refNum, 0L)) != noErr) {
  143.             ErrorMessage(BADSETEOF);
  144.             return;
  145.         }
  146.         WriteTiff(refNum, MyBitMapPtr);
  147.     }
  148. }
  149.  
  150. void DoSaveAs(myBitMapPtr)
  151. BitMap *myBitMapPtr;
  152. {
  153.     WindowPtr theActiveWindow;
  154.     OSErr error;
  155.     
  156.     SFPUTFILE(where, &putPrompt, ¤tFName, nil, &reply);
  157.     if (reply.good == false)
  158.         return;
  159.     if (refNum >= 0)    /* If there was a previous file open, close it */
  160.         DoClose();
  161.     /* Set current file name to that just selected */
  162.     currentFName = *((Str63 *)(&(reply.fName)));
  163.     error = FSDELETE(¤tFName, reply.vRefNum);
  164.     if (error != fnfErr && error != noErr) {
  165.         ErrorMessage(BADDELETE);
  166.         return;
  167.     }
  168.     if ((CREATE(¤tFName, reply.vRefNum, CREATOR, FILETYPE)) != noErr) {
  169.         ErrorMessage(BADCREATE);
  170.         return;
  171.     }
  172.     if ((FSOPEN(¤tFName, reply.vRefNum, &refNum)) != noErr) {
  173.         ErrorMessage(BADOPEN);
  174.         refNum = -1;
  175.         return;
  176.     }
  177.     theActiveWindow = FrontWindow();
  178.     SETWTITLE(theActiveWindow, ¤tFName);
  179.     
  180.     WriteTiff(refNum, myBitMapPtr);
  181. }
  182.  
  183. void DoQuitCleanUp(myBitMapPtr)
  184. BitMap    *myBitMapPtr;
  185. {
  186.     DoClose();
  187.     ClearImage(myBitMapPtr);
  188. }